#!/bin/bash
set -ex
#set -e
# -------------------------------------------------------------------------------
# Filename:     deploy_env_s.sh
# UpdateDate:   2025/07/18
# Description:  一键搭建 LMDeploy 验证环境。
# Example:      cd /home/share/pytorch2.5/lmdeploy/tools/ && bash deploy_env_s.sh
# Depends:      cambricon_pytorch_container-v25.01-torch2.5.0-torchmlu1.24.1-ubuntu22.04-py310.tar.gz
# Notes:        本脚本适用于初次进入docker容器环境；不适用于再次进入容器，可能会有意想不到问题
# -------------------------------------------------------------------------------

# 1. 使用 Cambricon Pytorch docker 镜像并激活“pytorch_infer”虚拟环境.
source /torch/venv3/pytorch_infer/bin/activate
# 2. 安装特定版本的lmdeploy
#pip install https://github.com/InternLM/lmdeploy/archive/refs/tags/v0.9.2.zip
pip install lmdeploy==0.9.2 --no-deps
# 3.安装依赖项（以下根据requirements.txt结合官方docker镜像已有的组件，筛选出独立安装的依赖库）
#pip install -r requirements.txt
pip install mmengine shortuuid peft==0.14.0 pynvml mmengine-lite fire gradio
# 4. 拷贝适配后的代码替换原来的代码
cp -rvf /home/share/pytorch2.5/lmdeploy/tools/utils.py /torch/venv3/pytorch_infer/lib/python3.10/site-packages/lmdeploy/cli/utils.py
cp -rvf /home/share/pytorch2.5/lmdeploy/tools/logits_process.py /torch/venv3/pytorch_infer/lib/python3.10/site-packages/lmdeploy/pytorch/engine/logits_process.py
#cd /workspace/ && git clone https://github.com/InternLM/lmdeploy.git && cd lmdeploy && git checkout 9098ae8 && git apply lmdeploy_mlu.patch

# 启动lmdeploy服务
#lmdeploy serve api_server /data/models/llm/models/Qwen2.5-7B-Instruct_fp16 --server-port 23333 --dtype=float16
# 启动客户端测试
## 使用LMDeploy客户端测试（交互式验证）​
#lmdeploy serve api_client http://localhost:23333
## 启动Gradio网页界面（可视化验证）​浏览器访问http://127.0.0.1:6006
#新终端中启动Gradio前端：
#lmdeploy serve gradio http://localhost:23333   --server-name 0.0.0.0   --server-port 6006
#浏览器访问:
#http://127.0.0.1:6006
